home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / psion / src.doc / unsorted / opl_c / callc.opl next >
Text File  |  1984-10-28  |  935b  |  48 lines

  1. REM CALLC.OPL
  2.  
  3. REM Example program to demonstrate calling C from OPL
  4.  
  5. REM Martin J Budden
  6. REM October 28 1992
  7.  
  8. PROC Main:
  9.     GLOBAL CCode%(27)    REM OPL.BIN is 54 bytes long
  10.     LOCAL Ret%
  11.  
  12.     Ret% = Bin2Buf%:(ADDR(CCode%()),"M:\OPO\OPL.BIN")
  13.     IF Ret%
  14.         PRINT "Error opening OPL.BIN:"
  15.         PRINT ERR$(Ret%)
  16.         GET
  17.         STOP
  18.     ENDIF
  19.     Ret% = USR(ADDR(CCode%()),1,0,0,0)
  20.     PRINT "C function 1 returns",Ret%
  21.     Ret% = USR(ADDR(CCode%()),2,0,0,0)
  22.     PRINT "C function 2 returns",Ret%
  23.     Ret% = USR(ADDR(CCode%()),3,0,0,0)
  24.     PRINT "C function 3 returns",Ret%
  25.     GET
  26. ENDP
  27.  
  28. PROC Bin2Buf%:(Addr%,File$)
  29.     REM load contents of File$ to buffer at Addr%
  30.  
  31.     LOCAL Fcb%,Ret%,pBuf%
  32.  
  33.     ret% = IOOPEN(Fcb%,File$,$400)
  34.     IF Ret% :RETURN Ret% :ENDIF
  35.     pBuf% = Addr%
  36.     WHILE 1
  37.         Ret% = IOREAD(Fcb%,pBuf%,512)
  38.         IF Ret%<0
  39.             IF Ret%=-36 REM EOF
  40.                 Ret% = 0
  41.             ENDIF
  42.             IOCLOSE(Fcb%)
  43.             RETURN Ret%
  44.         ENDIF
  45.         pBuf% = pBuf% + Ret%
  46.     ENDWH
  47. ENDP
  48.